import std/unicode
import std/unittest
import aibohphobia

from std/strutils import startsWith

const palindromes = ["", "a", " ", "ç", "😍", "gg", "))", "¾¾", "⛲⛲", "TNT", "h h", "løl", "ßuß", "úẇú", "👩👨👩", "666", "😭😭😭", "ABBA", "🔶🔷🔷🔶", "ππππ", "#hasah#", "SaippuakivikauppiaS", "SaippuakalasalakauppiaS"]
const nonpalindromes = ["ab", "K ", "Rr", "()", "ée", "💵💶", "wtf", "ahá", "noN", "💜💜💛", "tete", "ñññn", "😺💩😺😺", ".:,;'", "letter", "nissan", "👔👕👖👗👘👙👚", "not a palindrome"]
const strs = @palindromes & @nonpalindromes

suite "isPalindrome":
  test "isPalindrome positives":
    for palindrome in palindromes:
      check palindrome.isPalindrome
  test "isPalindrome negatives":
    for nonpalindrome in nonpalindromes:
      check not nonpalindrome.isPalindrome

suite "palindromize":
  test "minimally palindromize palindromes":
    for palindrome in palindromes:
      check palindrome.palindromize(minimal = true) == palindrome
  test "minimally palindromize non-palindromes":
    for nonpalindrome in nonpalindromes:
      let palindromized = nonpalindrome.palindromize(minimal = true)
      check palindromized.isPalindrome
      check palindromized.runeLen < 2 * nonpalindrome.runeLen
      check palindromized.startsWith(nonpalindrome)
  test "wastefully palindromize everything":
    for str in strs:
      let palindromized = str.palindromize(minimal = false)
      check palindromized.isPalindrome
      check palindromized.runeLen == max(2 * str.runeLen - 1, 0)
      check palindromized.startsWith(str)
